#include <iostream>
using namespace std;
#include <string>

template <typename T>
void sort(T* ary, int len, bool(*cmp)(T,T))
{
	if(0 == ary)	return ;

	for(int i = 0; i < len - 1; i++){
		for(int j = 0; j < len -i - 1; j++){
			if(cmp(ary[j + 1], ary[j])){
				T tmp = ary[j];
				ary[j] = ary[j + 1];
				ary[j + 1] = tmp;
			}
		}
	}
}

template <typename T>
void print(T* ary, int len)
{
	for(int i = 0; i < len; i++){
		cout << ary[i] << endl;
	}
}

class Fruit{
friend ostream& operator << (ostream& out, const Fruit& rhs);
private:
	string 	name;
	double 	price;
public:
	Fruit(const string& name, double price)
		:name(name),
		price(price)
	{
	
	}

	bool operator < (const Fruit& rhs) const 
	{
		return this->price < rhs.price;
	}
};

ostream& operator << (ostream& out, const Fruit& rhs)
{
	out << rhs.name << "\t" << rhs.price;
	return out;
}

template <typename T>
bool cmp(T x, T y)
{
	return x < y;
}
//偏特化  全特化   函数只有全特化   类有全特化和偏特化
int main(void)
{
	//int ary[10] = {3,4,5,6,7,1,2,11,99,0};

	//double ary_d[5] = {4.5, 8.9, 1.1, 0.9, 100};
	
	Fruit fruits[3] = {Fruit("apple", 4.5), Fruit("pear", 1.8), Fruit("banana", 3.7)};

	//string strs[3] = {"hello", "abc", "def"};
	//sort(ary, sizeof(ary) / sizeof(int), cmp);
	//sort(ary_d, 5, cmp);
	sort(fruits, 3, cmp);
	//sort(strs, 3, cmp);
	print(fruits, 3);
	
	return 0;
}
